//
//  ProgressBarView.m
//  test3
//
//  Created by 刘晓萌 on 15/12/29.
//  Copyright © 2015年 刘晓萌. All rights reserved.
//

#import "ProgressBarView.h"

#define getProgressWidth(num) ((self.frame.size.width/100) * num)

@interface ProgressBarView ()

@property (strong, nonatomic) UIView *progressView;
@property (strong, nonatomic) UIImageView *bottomImageView;
@property (strong, nonatomic) UIImageView *progressImageView;

@end


@implementation ProgressBarView

#pragma mark --- 初始化

/**
 * 便利构造器
 */
+(instancetype)progressBarViewInstanceByFrame:(CGRect)frame andProgressNum:(CGFloat)progressNum{
    ProgressBarView *pbView = [[ProgressBarView alloc]initWithFrame:frame];
    pbView.progressNum = progressNum;
    [pbView setView];
    return pbView;
}



#pragma mark --- 功能页

/**
 * 设置界面
 */
-(void)setView{
    
    self.backgroundColor = [UIColor colorWithRed:225.0f/255.0f green:235.0f/255.0f blue:230.0f/255.0f alpha:1.0f];;
    
    //底层label
    CGFloat width = getProgressWidth(self.progressNum);
    self.progressView = [[UIView alloc]initWithFrame:CGRectMake(1,1,width-1,self.frame.size.height-2)];
    self.progressView.backgroundColor =  [UIColor colorWithRed:101.0f/255.0f green:144.0f/255.0f blue:125.0f/255.0f alpha:1.0f];
    [self addSubview:self.progressView];
    //统一圆头
    [self setMask:self];
    [self setMask:self.progressView];
    
}

/**
 * 设置为圆
 */
-(void)setMask:(UIView *)sender{
    sender.layer.masksToBounds = YES;
    sender.layer.cornerRadius = sender.frame.size.height/2;
}

@end
